package com.daimler.itffo.uvs.kern;


public class Code implements Comparable<Object>{

//	private static final Code MODEL_JAHR_00 = new Code("800");
	private static final Code MODEL_JAHR_01 = new Code("801");
	private static final Code MODEL_JAHR_02 = new Code("802");
	private static final Code MODEL_JAHR_03 = new Code("803");
	private static final Code MODEL_JAHR_04 = new Code("804");
	private static final Code MODEL_JAHR_05 = new Code("805");
	private static final Code MODEL_JAHR_06 = new Code("806");
	private static final Code MODEL_JAHR_07 = new Code("807");
	private static final Code MODEL_JAHR_08 = new Code("808");
	private static final Code MODEL_JAHR_09 = new Code("809");
	private static final Code EMPTYCODE = new Code("");
	private static final Code DUMMYREPL_CODE= new Code("ZZZ");


	String code;

	public static Code createDummyReplCode() {
		return new Code("ZZZ");
	}

	public static Code createNewModelYear00Code() {
		return new Code("800");
	}

	public boolean isDummyReplCode() {
		return this.equals(DUMMYREPL_CODE);
	}

	public boolean isEmptyCode() {
		return this.equals(EMPTYCODE);
	}

	public Code(String code) {
		super();

		this.code = code.trim();

		switch (this.code.length()) {
		case 0:
			break;
		case 3:
			break;
		case 5:
			this.code = this.code.substring(2, 5);
			break;
		default:

			System.out.println("Code: " + this.code + " has wrong length");
			//System.exit(1);
		}
	}
	public boolean isModelJahrCode() {
		if(this.equals(MODEL_JAHR_09))
			return true;
		if(this.equals(MODEL_JAHR_08))
			return true;
		if(this.equals(MODEL_JAHR_07))
			return true;
		if(this.equals(MODEL_JAHR_06))
			return true;
		if(this.equals(MODEL_JAHR_05))
			return true;
		if(this.equals(MODEL_JAHR_04))
			return true;
		if(this.equals(MODEL_JAHR_03))
			return true;
		if(this.equals(MODEL_JAHR_02))
			return true;
		if(this.equals(MODEL_JAHR_01))
			return true;

		return false;
	}

	public String getCode() {
		return code;
	}

	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((code == null) ? 0 : code.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Code other = (Code) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		return true;
	}

	public int compareTo(Object o) {
		Code compareCode = (Code) o;
		return this.code.compareTo(compareCode.getCode());
	}

}
